//
//  NSObject+MDHNSObject.h
//  JSTech
//
//  Created by 高得华 on 2019/4/24.
//  Copyright © 2020 华&梅. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "MDHPTProtocol.h"

#if __has_include(<MJRefresh/MJRefresh.h>)
#import <MJRefresh/MJRefresh.h>
#else
#import "MJRefresh.h"
#endif

NS_ASSUME_NONNULL_BEGIN


// Formatting hints
typedef NS_ENUM(NSUInteger, MDHDateFormatHint) {
    MDHDateFormatHintNone = 0,
    MDHDateFormatHintRFC822,
    MDHDateFormatHintRFC3339,
};


//MARK: - ===== NSObject
@interface NSObject (MDHNSObject)

/// 获取 [from to] 之间的数据
+ (NSInteger) mh_randomNumberWithFrom:(NSInteger)from to:(NSInteger)to;

/// 根据获取到的
- (void)mh_convertNotification:(NSNotification *_Nullable)notification completion:(void (^ __nullable)(CGFloat duration, UIViewAnimationOptions options, CGFloat keyboardH))completion;


#pragma mark - Get..
/// Get class
- (BOOL)mh_isStringClass;
- (BOOL)mh_isNumberClass;
- (BOOL)mh_isArrayClass;
- (BOOL)mh_isDictionaryClass;
- (BOOL)mh_isStringOrNumberClass;
- (BOOL)mh_isNullOrNil;
- (BOOL)mh_isExist;

/// Get value
- (NSString *_Nullable)mh_stringValueExtension;

+ (id)loadInfo:(Class)aclass withKey:(NSString *)key;

+ (void)saveInfo:(NSObject *)obj withKey:(NSString *)key;


@end

NS_ASSUME_NONNULL_END


//MARK: - ====== CommonBlock ===== -
typedef void (^CommonVoidBlock)(void);

typedef void (^CommonBlock)(id selfPtr);

typedef void (^CommonCompletionBlock)(id selfPtr, BOOL isFinished);

@interface NSObject (CommonBlock)

- (void)excuteBlock:(CommonBlock)block;

- (void)performBlock:(CommonBlock)block;

//- (void)cancelBlock:(CommonBlock)block;

- (void)performBlock:(CommonBlock)block afterDelay:(NSTimeInterval)delay;

- (void)cancelPerformBlock:(CommonBlock)block;

- (void)excuteCompletion:(CommonCompletionBlock)block withFinished:(NSNumber *)finished;

- (void)performCompletion:(CommonCompletionBlock)block withFinished:(BOOL)finished;

// 并发执行tasks里的作务，等tasks执行行完毕，回调到completion
- (void)asynExecuteCompletion:(CommonBlock)completion tasks:(CommonBlock)task, ... NS_REQUIRES_NIL_TERMINATION;

@end






//MARK: - ===== UIViewController
@interface UIViewController (MDHUIViewController)
<
MMWDHObserveNavBackButtonHandlerProtocol
>

@end


//MARK: - ===== UIScrollView
@interface UIScrollView (MDHUIScrollView)
/// 添加下拉刷新控件
- (MJRefreshStateHeader *_Nullable)mh_addHeaderRefresh:(void(^_Nullable)(MJRefreshStateHeader * _Nullable header))refreshingBlock;
/// 添加上拉加载控件
- (MJRefreshAutoStateFooter *_Nullable)mh_addFooterRefresh:(void(^_Nullable)(MJRefreshAutoStateFooter * _Nullable footer))refreshingBlock;
@end



//MARK: - ===== UIColor
@interface UIColor (MDHColor)

+ (UIColor *)colorWithHexStr:(NSString *)color alpha:(CGFloat)alpha;

@end


//MARK: - ===== NSDate
// A category to parse internet date & time strings
@interface NSDate (MDHDate)


// Get date from RFC3339 or RFC822 string
// - A format/specification hint can be used to speed up,
//   otherwise both will be attempted in order to get a date
+ (NSDate *)dateFromInternetDateTimeString:(NSString *)dateString
                                formatHint:(MDHDateFormatHint)hint;

// Get date from a string using a specific date specification
+ (NSDate *)dateFromRFC3339String:(NSString *)dateString;
+ (NSDate *)dateFromRFC822String:(NSString *)dateString;

@end


//MARK: - ===== UIImage
// A category to parse internet date & time strings
@interface UIImage (MDHImage)

///获取图片
+ (UIImage *_Nullable)imageNamed_dh:(NSString *_Nullable)name;

///获取是否加密的图片
+ (UIImage *_Nullable)imageNamed_dh:(NSString *_Nullable)name decrypt:(BOOL)isDecrypt;

///压缩图片 到指定的大小
+ (UIImage *)compressImageQuality:(UIImage *)image toByte:(NSInteger)maxLength;

+ (UIImage *)sd_animatedGIFNamed:(NSString *)name;

+ (UIImage *)sd_animatedGIFWithData:(NSData *)data;

- (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size;

@end
